package com.validation.factory;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Administrator
 */
public interface EncryptionService {
    String encrypt(Object value);

    String decrypt(Object value);

    default void verifcationPhone(Object phone) {
        if (phone == null) {
            throw new IllegalArgumentException("手机号不能为空");
        }

        String PHONE_REGEX = "^1[3-9]\\d{9}$";
        Pattern PHONE_PATTERN = Pattern.compile(PHONE_REGEX);
        Matcher PHONE_MATCHER = PHONE_PATTERN.matcher(String.valueOf(phone));
        if (PHONE_MATCHER.matches()) {
            return;
        }
        throw new IllegalArgumentException("手机号不合法不正确");
    }

    default void verifcationIdCard(Object idCard) {
        if (idCard == null) {
            throw new IllegalArgumentException("身份证号码不能为空");
        }

        String CN_REGEX = "^[1-9]\\d{5}\\d{4}((0[1-9])|(10|11|12))((0[1-9])|([1-2][0-9])|30|31)\\d{3}[\\dX]$";
        String HK_REGEX = "^[A-Z]{1,2}\\d{6}(\\([A-Z]\\))?$";
        Pattern CN_PATTERN = Pattern.compile(CN_REGEX);
        Matcher CN_MATCHER = CN_PATTERN.matcher(String.valueOf(idCard));
        if (CN_MATCHER.matches()) {
            return;
        } else {
            Pattern HK_PATTERN = Pattern.compile(HK_REGEX);
            Matcher HK_MATCHER = HK_PATTERN.matcher(String.valueOf(idCard));
            if (HK_MATCHER.matches()) {
                return;
            }
        }
        return;
//        throw new IllegalArgumentException("身份证不正确");
    }
}
